<template>
  <div>
    <mt-header title="chatOnline">
      <mt-button
        slot="right"
        v-if="$route.path==='/chat'"
        class="app-logout-btn"
        @click.native="logout"
      >退出</mt-button>
    </mt-header>
    <router-view></router-view>
  </div>
</template>

<script>
import jsCookie from 'js-cookie'
import { MessageBox } from 'mint-ui'
import {Toast} from 'mint-ui'

export default {
  name: 'app',
  methods: {
    logout() {
      MessageBox.confirm('确定执行此操作?').then(() => {
        //清除服务器上已登录的用户名
        this.$axios.get('/api/logout').then(data => {
          if (data.data.code === 0) {
            //退出删除cookie并刷新页面
            jsCookie.remove('userid')
            this.$router.go(0)
          }
        })
      }).catch(()=>{
        Toast('取消退出')
      })
    }
  }
}
</script>

<style scoped>
.app-logout-btn {
  cursor: pointer;
}
</style>
